﻿function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//选中下拉框
function doSelect(targetObj,selectedValue){
	for(i=0;i<targetObj.options.length;i++){
		if(targetObj.options[i].value==selectedValue){
			targetObj.options[i].selected=true;
			break;
		}
	}
}

//选中单选框
function doRadioSelect(radioName,selectedValue){
	radioArray = document.getElementsByName(radioName);
	for(i=0;i<radioArray.length;i++){
		if(radioArray[i].value==selectedValue){
			radioArray[i].checked=true;
			break;
		}
	}
}
//设置当前路径
function setLocation(str){
	var div = top.document.getElementById("curLocation");
	div.innerHTML="运营商管理系统 &gt; " + str;
}
//父窗口调用此方法
function openWin(winTitle,winURL,width,height,callback){
	var winWidth = width==null?($(window).width() - 100):width==-1?($(parent).width() - 100):width;
	var winHeight = height==null?($(window).height() - 100):height==-1?($(parent).height() - 100):height;

	var leftWidth = ($(parent).width()-winWidth)/2;
	
	parent.$.layer({
        type: 2,
        maxmin: false,
        title: winTitle,
        offset: ['50px', leftWidth + 'px'],
        area: [winWidth +'px', winHeight+'px'],
        iframe: {src: winURL},
        close: function(index){closeWin();}
    }); 
	
	//保存callback，根据子窗口的index来索引
	if(callback && typeof(callback) === "function"){
		share.data(parent.layer.index,callback);
	}
 }
 
 //此方法由子窗口调用，故window.name是iframe页面的name
 function closeWin(data){
	 
	 //取得callback
	 var callback = share.remove(parent.layer.getFrameIndex(window.name));
	 if(callback && typeof(callback) === "function"){
		 //callback初始是由父窗口创建的，所以此时回调时，仍然是父窗口执行的。
		 callback(data);
	 }
	 
	 //关闭窗口
	 parent.layer.close(parent.layer.getFrameIndex(window.name));
 }
 
 
 var share = {

 	/**
 	 * 跨框架数据共享接口
 	 * @param	{String}	存储的数据名
 	 * @param	{Any}		将要存储的任意数据(无此项则返回被查询的数据)
 	 */
 	data: function (name, value) {
 		var top = window.top,
 			cache = top['_CACHE'] || {};
 		top['_CACHE'] = cache;
 		
 		return value !== undefined ? cache[name] = value : cache[name];
 	},
 	
 	/**
 	 * 数据共享删除接口
 	 * @param	{String}	删除的数据名
 	 */
 	remove: function (name) {
 		var cache = window.top['_CACHE'];
 		var value = null;
 		if (cache && cache[name]){
 			value = cache[name];
 			delete cache[name];
 		}
 		return value;
 	}
 	
 };